//
// Created by lfm on 25-4-14.
//

// #include "Time.h"
#include <iostream>
using namespace std;
class Time
{
public:
    Time(int h = 0 , int m = 0, int s = 0);
    Time operator+(const Time& t); //重载+
    void Display(); //显示时间

private:
    int m_Hours; //时

    int m_Minutes; //分

    int m_Seconds; //秒

};


Time::Time(int h, int m , int s)
{
    this->m_Hours = h;
    this->m_Minutes = m;
    this->m_Seconds = s;
    //处理进位
    if (m_Seconds >= 60)
    {
        m_Minutes += m_Seconds / 60;//64 / 60  = 1
        m_Seconds %= 60;
    }
    if (m_Minutes >= 60)
    {
        m_Hours += m_Minutes / 60;
        m_Minutes %= 60;
    }
    if (m_Hours >= 24)
    {
        m_Hours %= 24;
    }
    if (m_Hours < 0)
    {
        m_Hours = 0;
    }
    if (m_Minutes < 0)
    {
        m_Minutes = 0;
    }
    if (m_Seconds < 0)
    {
        m_Seconds = 0;
    }
}
Time Time::operator+(const Time& t)
{
    Time tmp(0, 0 ,0);
    tmp.m_Hours = this->m_Hours + t.m_Hours;
    tmp.m_Minutes = this->m_Minutes + t.m_Minutes;
    tmp.m_Seconds = this->m_Seconds + t.m_Seconds;
    //处理进位
    if (tmp.m_Seconds >= 60)
    {
        tmp.m_Minutes += tmp.m_Seconds / 60;
        tmp.m_Seconds %= 60;
    }
    if (tmp.m_Minutes >= 60)
    {
        tmp.m_Hours += tmp.m_Minutes / 60;
        tmp.m_Minutes %= 60;
    }
    if (tmp.m_Hours >= 24)
    {
        tmp.m_Hours %= 24;
    }
    if (tmp.m_Hours < 0)
    {
        tmp.m_Hours = 0;
    }
    return tmp;
}
void Time::Display()//显示时间
{
    cout << m_Hours << ":" << m_Minutes << ":" << m_Seconds << endl;
}

